package cn.webrx.coll;/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */

import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

/**
 * <p>Project: jse2204 - cn.webrx.coll.HashMap2
 * <p>Powered by webrx On 2022-09-20 09:17:32
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class HashMap2 {
    public static void main(String[] args) {
        //声明数组，数组是对象，是引用类型
        int[] ii = new int[3];
        User[] us = new User[4];

        //Map接口  实现类HashMap  TreeMap
        //Map<String, int[]> map1 = new HashMap<>();
        //Map<String, Integer> map2 = new HashMap<>();

        HashMap<String,String> ss = new HashMap<>();
        ss.put("s1","lisi");
        ss.put("s2","张三");
        ss.remove("s2");
        System.out.println(ss.size());
        ss.replace("s1","李四");
        System.out.println(ss);
        ss.clear();
        System.out.println(ss.size());

        ss.put("z1","aa");
        ss.put("z2","bb");
        ss.put("z3","cc");
        ss.put("z4","ddddd");

        System.out.println(ss);
        Set<String> keys = ss.keySet();
        Collection<String> values = ss.values();

        //遍历
        for(String k : keys){
            System.out.println(k + "=" + ss.get(k));
        }

        for(String v : values){
            System.out.printf("%s%n",v);
        }

        ss.forEach((k,v)->{
            System.out.println(k + "=" + ss.get(k));
        });

        System.out.println(ss.containsValue("aa"));
        System.out.println(ss.containsKey("z6"));

    }
}
